
package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import yunhe.biz.StockMgrBiz;
import yunhe.biz.impl.StockMgrBizImpl;

@WebServlet(name="SaveTakingMsgServlet",urlPatterns="/SaveTakingMsgServlet")
public class SaveTakingMsgServlet extends HttpServlet
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req,resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{  
		String reposity=req.getParameter("reposity");
		HttpSession session=req.getSession();
		
		String takcode=(String) session.getAttribute("Takcode");
		
		String rows=req.getParameter("rowdata");
		
		 try
		{
			JSONArray ja=new JSONArray(rows);
		System.out.println(ja.toString());
		Date date=new Date(new java.util.Date().getTime());	
		
		SimpleDateFormat s=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time=s.format(date);
		
			for(int i=0;i<ja.length();i++)
			{
				JSONObject jo=  (JSONObject) ja.get(i);
				System.out.println(jo.toString());
				String proBarCode=jo.getString("proBarCode");
				int prolossNum=jo.getInt("proLossCount");
				double prolossPrice=jo.getDouble("proLossMoney");
				int preinvCount=jo.getInt("preinvCount");
				int invCount=jo.getInt("invCount");
				
       Object[] params={takcode,reposity,proBarCode,invCount,preinvCount,prolossNum,prolossPrice,0};
       StockMgrBiz stock=new StockMgrBizImpl();
       int j=stock.insertIntoTaking(params);

      PrintWriter out=resp.getWriter();
       out.print(j);
			}
			
		} catch (JSONException e)
		{
	
			e.printStackTrace();
		}
		
	     
	}

}

